/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cl.innovision.generation;
import cl.innovision.helper.utils.Formateador;
import cl.innovision.vo.Procedure;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.LinkedList;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;

/**
 *
 * @author Patricio
 */
public class GeneradorRIA {
    
        private String genDir = "C:\\Users\\PATO\\Documents\\NetBeansProjects\\InnoGen\\";
    private String project = "demo";
    private String modulo = "test";
    private Formateador u = null;

    public GeneradorRIA(String genDir,String project,String modulo) {
        this.genDir=genDir;
        this.project=project;
        this.modulo=modulo;
        this.genDir = this.genDir;
        u = new Formateador(project, modulo);

    }
    
     public void genHTML5(cl.innovision.vo.shema.ventanas.Ventanas.Ventana ventana) {
        VelocityContext context = new VelocityContext();
        context.put("v", ventana);
        context.put("u", u);

        try {
            String genDir = this.genDir   + "/html";
            (new File(genDir)).mkdirs();
            String filename = genDir + "/" + Formateador.firstToUpperCase( ventana.getNombreVentana())  + ".html";
            Template template = Velocity.getTemplate("template/oracle/html.vm");
            BufferedWriter writer = new BufferedWriter(new FileWriter(filename));
            template.merge(context, writer);
            writer.flush();
            writer.close();
        } catch (ResourceNotFoundException e) {
            //log.fatal("No pudo encontrar un recurso", e);
            System.out.println("No pudo encontrar un recurso" + e.getMessage());
           // System.exit(1);
        } catch (ParseErrorException e) {
            //log.fatal("No pudo generar clase", e);
            System.out.println("No pudo generar clase" + e.getMessage());
           // System.exit(1);
        } catch (Exception e) {
            System.out.println("No pudo generar clase" + e.getMessage());
            //log.fatal("No pudo generar clase", e);
          //  System.exit(1);
        }


        System.out.println("Archivo " + "HTML generada");
    }
}
